home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
adatimer.zip
/
TIMEL3.ADA
< prev
next >
Wrap
Text File
|
1990-06-07
|
3KB
|
112 lines
-- PTD.ada
with POLLED_TIMER;
with DIM_FLOAT, ASCII_UTILITIES;
-- DIM_FLOAT and ASCII_UTILITIES are
-- from Ada in Action by Do-While Jones,
-- John Wiley & Sons, Inc.
with TEXT_IO;
procedure Polled_Timer_Demo is
I : integer := 0;
type Seconds is new DIM_FLOAT.Units;
USED, LEFT : Seconds;
LEFT1, LEFT2, LEFT3, LEFT4 : Seconds;
package TIMER is new POLLED_TIMER(Seconds);
procedure Put(MSEC : Seconds) is
begin
-- Multiply by 1000 to show milliseconds.
TEXT_IO.Put(ASCII_UTILITIES.Fixed_Image
(Dimensionless(MSEC) * 1000.0));
end Put;
begin
TEXT_IO.Put_Line("Fast Polled Timer Demo");
-- Show single mode
TIMER.Set(+0.050,TIMER.SINGLE);
TEXT_IO.Put_Line("Starting 50 msec timer.");
TIMER.Start;
TIMER.Stop;
LEFT := TIMER.Time_Left;
Put(LEFT); TEXT_IO.Put_Line(" msec left.");
TIMER.Start;
TEXT_IO.Put_Line
("Let's see how long it took to write this line.");
TIMER.Stop;
USED := TIMER.Time_Used;
Put(USED); TEXT_IO.Put_Line(" msec used.");
TEXT_IO.Put_Line
("Resetting the timer.");
TIMER.Restart;
TIMER.Stop;
LEFT := TIMER.Time_Left;
Put(LEFT); TEXT_IO.Put_Line(" msec left.");
TEXT_IO.Put_Line("Looping until the timer expires.");
TIMER.Start;
I := 0;
while not TIMER.Has_Expired loop
I := I+1;
end loop;
TEXT_IO.Put_Line("Timer expired after" &
integer'IMAGE(i) & " loops.");
-- Show reset and read-on-the-fly
TEXT_IO.Put_Line("Reading the timer on the fly.");
TIMER.Restart;
LEFT1 := TIMER.Time_Left;
LEFT2 := TIMER.Time_Left;
LEFT3 := TIMER.Time_Left;
LEFT4 := TIMER.Time_Left;
Put(LEFT1); TEXT_IO.Put_Line(" msec left.");
Put(LEFT2); TEXT_IO.Put_Line(" msec left.");
Put(LEFT3); TEXT_IO.Put_Line(" msec left.");
Put(LEFT4); TEXT_IO.Put_Line(" msec left.");
-- Show Stop and read while stopped.
TEXT_IO.Put_Line("Reading the timer when stopped.");
TEXT_IO.Put_Line("50 msec timer started.");
TIMER.Restart;
TIMER.Stop;
TEXT_IO.Put_Line("Stopped as soon as possible.");
USED := TIMER.Time_Used;
LEFT := TIMER.Time_Left;
Put(USED); TEXT_IO.Put_Line(" msec used.");
Put(LEFT); TEXT_IO.Put_Line(" msec left.");
TEXT_IO.Put_Line("1 second later.");
Delay(1.0);
USED := TIMER.Time_Used;
LEFT := TIMER.Time_Left;
Put(USED); TEXT_IO.Put_Line(" msec used.");
Put(LEFT); TEXT_IO.Put_Line(" msec left.");
TIMER.Start;
TIMER.Stop;
TEXT_IO.Put_Line("Let it run momentarily.");
USED := TIMER.Time_Used;
LEFT := TIMER.Time_Left;
Put(USED); TEXT_IO.Put_Line(" msec used.");
Put(LEFT); TEXT_IO.Put_Line(" msec left.");
-- Show repeat mode
TIMER.Set(+0.05,TIMER.REPEATED);
TEXT_IO.Put_Line
("Watching 1 second timer for 5 seconds.");
TIMER.Start;
for i in 1..5 loop
for j in 1..20 loop -- 20 * 50 msec = 1 sec
while not TIMER.Has_Expired loop null; end loop;
end loop;
TEXT_IO.Put_Line(" Tick");
end loop;
TIMER.Stop;
TEXT_IO.New_Line;
TEXT_IO.Put_Line("Done.");
end Polled_Timer_Demo;